<?php
// +----------------------------------------------------------------------
// | 青航系统 [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2023-永久 https://www.feifeiyu.club/ All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: 青航-不吃芒果 <1716892803@qq.com>
// +----------------------------------------------------------------------
namespace app\admin\controller;
use think\exception\Jump;
use think\facade\View;
class Group extends  Common{
    
    
	// 数据列表
	public function index(){
	    // 输出数组集合
	    $list = D('group')->order('groupid ASC')->paginate(15);
	    return view('group/index',['list'=>$list]);
	 }
	 
	 
	// 添加数据 
    public function add() {
    	if (request()->isPost()) {
    	    if(!input('post.name')) Jump::error('名称不能为空!');
    	    $k = input('post.');
            if($k['authority']) {
    			$k['authority'] = join(',',$k['authority']);
    		} else {
    			$k['authority'] = '';
    		}
    		$k['is_system'] = 0;
            $r = D('group')->insert($k,true);
           
    		if($r){
    		   Jump::success("添加成功!");
    		}
    		else {
    		   Jump::error('添加错误!!');
    		}
    	    
    	}
    	sleep(1);
    	return view('group/group_add');
    }
    
    
    
     // 修改数据
    public function edit() {
        // 获取网页中提交的ID
    	$groupid = request()->param('groupid');
    	// 	查询对应字段的参数
    	$find = D('group')->where('groupid',$groupid)->find();
    	if (request()->isPost()) {
    	    $k = input('post.');
            if($k['authority']) {
    			$k['authority'] = join(',',$k['authority']);
    		} else {
    			$k['authority'] = '';
    		}
    		$r = D('group')->where('groupid', $k['groupid'])->update($k);
            
    		if($r){
    		    Jump::success('更新成功!'); 
    		}
    		else {
    		    Jump::error('更新失败,数据未改动!'); 
    		}
    		
    	}
    	sleep(1);
    	return view('group/group_edit',['find'=>$find]);
    }
    
    
    
    
    // 多选删除
    public function dels() {
    	if (request()->isPost()) {
    	    // 判断是否获取到值
    		if(!input('param.fx'))Jump::error('没有选择项目!!');
    		// 再循环提交过来的值
    		foreach(input('param.fx') as $id) {
               $r = D('group')->where('groupid',$id)->delete();  
            }
         }
    	// 判断是否执行成功
    	if($r) {
    		Jump::success('删除成功!');
    	} else {
    		Jump::error('删除失败!');
    	}
    }        
    
	
	
	
}